package com.twotiger.and.activity.user;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import app.twotiger.p2p.R;

import com.twotiger.and.activity.HomeActivity;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.util.DigestUtils;
import com.twotiger.and.view.GesturePassWordView;

public class GesturePsdPage extends BaseActivity implements OnClickListener {

    private static final String TAG = "FindPasswordPage";
    private Button find_password_bt;
    private GesturePassWordView mGesturePassWordView;
    private boolean needverify = true;
    private int gesture_login_code = 14;
    private Button cut_account_bt;
    private Button forget_psd_bt;

    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.gesture_password_layout, null);
        return view;
    }

    @Override
    protected void findViewById(View view) {
        mGesturePassWordView = (GesturePassWordView) view.findViewById(R.id.mGesturePassWordView);
        cut_account_bt = (Button) view.findViewById(R.id.cut_account_bt);
        forget_psd_bt = (Button) view.findViewById(R.id.forget_psd_bt);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.sub_title_left_ll:
            popBackStack();
            break;
        case R.id.cut_account_bt://切换账号
            startNewActivity(new Intent(this, LoginPage.class), R.anim.push_left_in,
                R.anim.push_left_out, false);
            break;
        case R.id.forget_psd_bt://忘记启动密码
            startNewActivity(new Intent(this, ModifyLoginPwdPage.class), R.anim.push_left_in,
                R.anim.push_left_out, false);
            break;
        }
    }

    @Override
    protected void setListener() {
        cut_account_bt.setOnClickListener(this);
        forget_psd_bt.setOnClickListener(this);
    }

    @Override
    protected void processLogic() {
        mGesturePassWordView.setOnCompleteListener(new GesturePassWordView.OnCompleteListener() {
            @Override
            public void onComplete(String mPassword) {
                if (needverify) {
                    if (mGesturePassWordView.verifyPassword(DigestUtils.md5(mPassword))) {
                        showToast("密码输入正确,请输入新密码!");
                        mGesturePassWordView.clearPassword();
                        needverify = false;
                        Intent intent = new Intent(GesturePsdPage.this, HomeActivity.class);
                        startNewActivity(intent, R.anim.push_left_in, R.anim.push_left_out, false);
                        finish();
                    } else {
                        showToast("错误的密码,请重新输入!");
                        mGesturePassWordView.clearPassword();
                    }
                }
            }

            @Override
            public void onShortComplete(String password) {

            }
        });
    }

    @Override
    protected void onBackPress() {
        // TODO Auto-generated method stub

    }

}
